﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<title>查询科目类别列表</title>
<style>
.input_txt{
	width: 150px;
}
.table_list tbody tr{
	height: 30px;
}
</style>
</head>
<body>
	<div class="main_panel m_b20">
		<div class="ch_panel" id="queryDiv" style="width: 75.2002%;">
			<input type="hidden" data-qname="CSRFToken" id="CSRFToken" value="${csrfToken}" id="csrfToken" />
			<table>
				<tr>
					<td class="c_table">
						<input type="button" value="资产" id="zcBtn" data_value="ZC" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="负债" id="fzBtn" data_value="FZ" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="权益" id="qyBtn" data_value="QY" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="成本" id="cbBtn" data_value="CB" class="e_btn" style="margin-right: 5px;" />
						<input type="button" value="损益" id="syBtn" data_value="SY" class="e_btn" style="margin-right: 5px;" />
					</td>
					<c:if test="${isEdit }">
						<td class="t_r">
							<input type="button" value="保存" id="addBtn" class="a_btn" />
						</td>
					</c:if>
				</tr>
			</table>
		</div>
		<table class="table_list m_t10" style="width: 77%">
			<thead>
				<tr id="trA">
					<th width="10%">序号</th>
					<th width="15%">科目类别编码</th>
					<th width="45%">科目类别名称</th>
					<th width="10%">余额方向</th>
					<th width="20%">期初余额(元)</th>
				</tr>
			</thead>
		</table>
		<div style="height:77%;width: 77%;overflow: auto;border-bottom: 1px solid #ccc; background:#fff;">
			<table id="tbwrap" class="table_list"></table>
		<div/>
	</div>

	<script type="text/html" id="tb_template">
		<tbody data-type="body" id="tbodyB">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],index = i+1,classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td><!=index!></td>
					<td align="left"><!=item["dicCode"]!></td>

					<!if(item["levelNum"]=='2') { !>
							<td align="left" style="padding-left: 20px;">
					<!}else if(item["levelNum"]=='3') {!>
							<td align="left" style="padding-left: 40px;">
					<!}else if(item["levelNum"]=='4') {!>
							<td align="left" style="padding-left: 60px;">
					<!}else{!>
						<td align="left">
					<!}!>
						<!=item["dicName"]!>
					</td>
					<td>
						<!if(item["yueFx"]=='1') { !>
							借
						<!}else if(item["yueFx"]=='-1') {!>
							贷
						<!}!>	
					</td>

					<td align="left">
						<!if(item["chileCount"]<1) { !>
							<!if("${isEdit}"=="true") { !>
								<input type="text" class="input_txt" id="<!=item["uuid"]!>" placeholder="0.00" onkeyup="num(this)" onafterpaste="num(this)" style="text-align: right;font-size: 16px;" name="chuShiValue" value="<!=item["qiChuValue"]!>" />
							<!}else{!>
								<!=item["shiJiSunYiValue"]!>
							<!}!>
						<!}else{!>
							<!=item["shiJiSunYiValue"]!>
						<!}!>
					</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="10"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>

	<script type="text/javascript">
	
		var currKeMuFenLei;
		$(function () {

			//ajax请求添加等待图片
			$(document).ajaxStart(function () {
				ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 8000);
			});

			$(document).ajaxComplete(function () {
				ZENG.msgbox.hide();
			});

			// 1、资产
			$("#zcBtn").click(function () {
				onclickBtn(this);
				search($(this).attr("data_value"));
			});
			// 2、负债
			$("#fzBtn").click(function () {
				onclickBtn(this);
				search($(this).attr("data_value"));
			});
			// 3、权益
			$("#qyBtn").click(function () {
				onclickBtn(this);
				search($(this).attr("data_value"));
			});
			// 4、成本
			$("#cbBtn").click(function () {
				onclickBtn(this);
				search($(this).attr("data_value"));
			});
			// 5、损益
			$("#syBtn").click(function () {
				alert("年初启用的账套，不需要录入损益初始余额哦！");
				return;
				onclickBtn(this);
				search($(this).attr("data_value"));
			});

			$("#zcBtn").click();

			// 6、保存
			$("#addBtn").click(function () {
				var dataArray="";
				$.each($("#tbwrap input[name='chuShiValue']"), function(i, input){
					var inputValue = $(input).val();
					var uuid = $(input).attr("id");
				  	if(inputValue!=""){
				  		dataArray+=(uuid+"="+inputValue+",");
				  	}else{
				  		dataArray+=(uuid+"=0,");
				  	}
				});
				
				$.post("${ctx}/dickm/setChuShiYuE", {dataArray : dataArray,currKeMuFenLei : currKeMuFenLei}, function(result) {
					if ("succ" == result) {
						alert("操作成功");
					} else {
						alert(result);
					}
				},"json");
			});
			
		});

		function onclickBtn (thiss) {
			
			currKeMuFenLei = $(thiss).attr("data_value");
			
			$(".c_table :button").removeClass("f_btn");
			$(".c_table :button").removeClass("e_btn");
			$(".c_table :button").addClass("e_btn");

			$(thiss).removeClass("e_btn");
			$(thiss).removeClass("f_btn");
			$(thiss).addClass("f_btn");
		}
		
		function num(obj){
			obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
			obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
			obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
			obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
			obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
			if(obj.value.indexOf(".")>-1){
				if(obj.value.split(".")[0].length>9){
					obj.value=obj.value.substring(0,9)+obj.value.split(".")[1];
				}
				if(obj.value.split(".")[0].length>1 && parseInt(obj.value.split(".")[0].substring(0,1))==0){
					obj.value=obj.value.substring(1,obj.value.length);
				}
			}else{
				if(obj.value.length>9){
					obj.value=obj.value.substring(0,9);
				}
				if(obj.value.length>1 && parseInt(obj.value.substring(0,1))==0){
					obj.value=obj.value.substring(1,obj.value.length);
				}
			} 
		}
	</script>

	<script type="text/javascript">
		function search (leiBieValue) {
			seajs.use([ "component/table" ], function (uiTable) {
				$.post("${ctx}/dickm/ajaxList", {
					leiBie : leiBieValue
				}, function (result) {

					// 系统有异常信息
					if (JSON.stringify(result).indexOf("系统出现异常") >= 0) {
						alert(result);
						return;
					}

					var table = new uiTable({
						"con" : "#tbwrap", "data" : {
							"list" : result
						}, "template" : "tb_template"
					});
					
					$($($("#tbodyB tr").get(0)).find("td").get(0)).width($($("#trA th").get(0)).width());
					$($($("#tbodyB tr").get(0)).find("td").get(1)).width($($("#trA th").get(1)).width());
					$($($("#tbodyB tr").get(0)).find("td").get(2)).width($($("#trA th").get(2)).width());
					$($($("#tbodyB tr").get(0)).find("td").get(3)).width($($("#trA th").get(3)).width());
				});
			});
		}
	</script>
</body>
</html>